<%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>手动触发报表——恒拓运价魔方</title>
<%@ include file="/pages/common/header.jsp" %>

<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/show.js"></script>
<link href="<%=request.getContextPath() %>/fare/css/base.css" rel="stylesheet" type="text/css" /> 
<!-- 圆角文本框 -->
<link href="<%=request.getContextPath() %>/fare/css/htc/htc.css" rel="stylesheet" type="text/css" /> 
<link rev="stylesheet" media="all" href="<%=request.getContextPath() %>/fare/css/form_style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="<%=request.getContextPath() %>/jsFile/js_new/jquery.1.7.2.js"></script>
 <script type="text/javascript" src="<%=request.getContextPath()%>/fare/js/json2.js"></script>
 <script src="<%=request.getContextPath()%>/fare/lib/jquery/jquery.form.js"	type="text/javascript"></script>
 <script type="text/javascript" src="<%=request.getContextPath()%>/jsFile/multiblepicker.js"></script>
 <script type="text/javascript" src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/ligerui.min.js"></script>
<%-- <style type="text/css">
	.navbar{line-height:33px;height:33px;background:url('${pageContext.request.contextPath}/images/background/navbar.gif') repeat-x; width:100%; position:relative; margin-top:8px; margin-bottom:8px;}
		.navbar-l,.navbar-r{ width:2px;height:33px;background:url('${pageContext.request.contextPath}/images/background/navbar.gif') no-repeat; position:absolute; }
		.navbar-l{ left:0px; background-position:0px -33px;}
		.navbar-r{ right:0px;background-position:0px -66px;}
		.navbar-icon{ position:absolute; left:7px; top:6px;}
		.navbar img{ width:20px; height:20px;}
		.navbar-inner{ margin-left:30px;}
		.navbar a{ color:#3186C8;}
</style> --%>
<style type="text/css">
.tooltips{
text-decoration:none;
position:relative;
z-index:2;
}
.tooltips:hover{
z-index:3;
background:none;
}
.tooltips span{
display: none;
}
.tooltips:hover span{
z-index:99999;
display:block;
position:absolute;  
margin:-25px 0px 0px -25px; border:0;
clear:both;
overflow:hidden;
margin:0;
padding:0;
border:1px solid black;
background-color:#DCDCDC;
padding:3px;
color:black;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
	window.CHENKED_USERNAME=new Array();
	window.CHENKED_EMAIL=new Array();
	window.CHECKED_STR="(已选择)"; 
	
});


function checkForm(){
	var method =$('#method').val();
//	var start =$('#start').val();
//	var nowaday=new Date();
//	var d1=new Date(start.replace(/-/g,"\/"));
//	var d2=new Date(nowaday);
		
	
	var flag=true;
	if(method =='' || method=='--请选择--' || method ==null || method=='undefined'){
		flag=false;
		alert("请选择要发送的报表！");
		return;
	}
	/* if(start =='' || start==null || start=='undefined'){
		flag=false;
		alert("请选择发送时间！");
		return;
	}else{
		if((Date.parse(d1) < Date.parse(d2) )){
			flag=false;
			alert("发送时间日期不能小于当前时间日期！");
			return;
		}
	} */
 	if(CHENKED_EMAIL.length==0){
		flag=false;
		alert("请添加‘发送人’");
		return;
	}
	return flag;
}


//显示用户名（传入email地址）
function showUsers(){
	$("#usernames option").remove();
	clearAll();
	var method =$('#method').val();
	if(method !=null && method !='' && method !='undefined'){
		$("#usernames").append("<c:forEach var='item' items='${emailList}'> <option value='${item.emailAddress}' name='userNameList'>${item.userName}</option></c:forEach> ");
		
	}
}

//添加或删除被选择的收件人
function addOrRemoveChioce(e){
	//alert(CHENKED_EMAIL+' '+$(e).val()+' '+$(e).get(0).selectedIndex+' '+CHENKED_USERNAME+'  '+$(e).get(0).options[$(e).get(0).selectedIndex].text);
	var str=CHENKED_EMAIL.join("|");
	var str_2=CHENKED_USERNAME.join("|");
	var op=$(e).find("option:selected");
	if(str.indexOf($(e).val())==-1 ){//不存在该用户
		CHENKED_EMAIL.unshift($(e).val());//放入
		CHENKED_USERNAME.unshift($(e).get(0).options[$(e).get(0).selectedIndex].text);
		$(op).text($(op).text()+CHECKED_STR);
	}else{//存在
		str=str.replace($(e).val(),"");
		str_2=str_2.replace($(e).get(0).options[$(e).get(0).selectedIndex].text,"");
		var strs=str.split("|");
		var strs_2=str_2.split("|");
		CHENKED_EMAIL=[];
		CHENKED_USERNAME=[];
		for(var i=0;i<strs.length;i++){
			if(strs[i]!=null && $.trim(strs[i])!="" && strs[i]!="|"){
				CHENKED_EMAIL.push(strs[i]);
				CHENKED_USERNAME.push(strs_2[i]);
			}
		};
		$(op).text($(op).text().replace(CHECKED_STR,""));
	//	$(op).text($(op).val().replace(CHECKED_STR,""));
	}
	flushCheckedFlights();
	
}

//刷新已经选择的用户
function flushCheckedFlights(){
	
	var table=$("#username");
	$(table).empty();
	var rowSize=5;//一行容纳多少个用户，动态的生成表格
	for(var i=1;i<=CHENKED_EMAIL.length;i++){
		if(i%rowSize==1){
			table.append("<tr></tr>");
		}
		$("tr:last",table).append("<td style='padding:5px 5px 5px 0px;border-bottom:0px;'>"
		+"<input type='checkbox' name='usernameList' value='"+CHENKED_EMAIL[i-1]+"' checked='checked'  onclick='changeChecked(this)'/>&nbsp&nbsp"+CHENKED_USERNAME[i-1]
		+"</td>");
	}
}

//改变选项
function changeChecked(e){
	if($(e).attr("checked")!=true){//不选则删除他，同时需要改变select的显示方式还有全局变量
		var str=CHENKED_EMAIL.join("|");
		str=str.replace($(e).val(),"");
		var strs=str.split("|");
		
		var str_2=CHENKED_USERNAME.join("|");
		str_2=str_2.replace($(e).text(),"");
		var strs_2=str_2.split("|");
		
		CHENKED_EMAIL=[];
		CHENKED_USERNAME=[];
		for(var i=0;i<strs.length;i++){
			if(strs[i]!=null && $.trim(strs[i])!="" && strs[i]!="|"){
				CHENKED_EMAIL.push(strs[i]);
				CHENKED_USERNAME.push(strs_2[i]);
			}
		};
		flushCheckedFlights();
		$("#usernames option").each(function(){
			if($(this).val()==$(e).val()){
		//    if($(this).text()==$(e).text()){
			//	$(this).text($(this).val());
				$(this).text($(this).text().split('(')[0]);
				return;
			}
		});
	}
}


function sendReport(){
	if(checkForm()){
		if(	confirm("确定发送此报表？")){
			$("#wait").show();
			$("#doEditForm").ajaxSubmit({
				url:"<%=request.getContextPath()%>/manualReportAction!sendReport.action",
				type:'post',
		//		dataType:'json',
				cache : false,
			    async : false,
			    
			    beforeSend:function(){},
			    success:function(data){
			    	if(data=='SUCCESS'){
			    		alert("报表生成成功，后台将发送报表");
			    	}else{
			    		alert("报表生成失败！失败原因："+data);
			    		return ;
			    	}
			    	$("#btn1").removeAttr("disabled");
			    	$("#wait").hide();
			    	window.location.href="<%=request.getContextPath() %>/manualReportAction!toIntoJSP.action";
			    },
			    error:function(){
			    	alert("报表发送错误！，请联系管理员！");
			    	$("#btn1").removeAttr("disabled");
			    	$("#wait").hide();
			    },
			    complete:function(){
			    	$("#btn1").removeAttr("disabled");
			    	$("#wait").hide();
			    }
			});
			
		}
	}
	
	
} 

//下载报表
function doDownloadFile(path,fileSubject){
	var filePath=encodeURI(encodeURI(path));
	var subjectName=encodeURI(encodeURI(fileSubject));
	window.location.href="<%=request.getContextPath() %>/manualReportAction!download.action?filePaths="+filePath+"&subjectNames="+subjectName;
	
	
}

//根据日期下载所有报表
function downloadAllByDate(dateStr){
	var reportCreateDates=encodeURI(encodeURI(dateStr));
	window.location.href="<%=request.getContextPath() %>/manualReportAction!downloadAllByDate.action?reportCreateDate="+reportCreateDates;
	
}

//清除所有选项
function clearAll(){
	CHENKED_EMAIL=[];
	CHENKED_USERNAME=[];
	flushCheckedFlights();
	$("#usernames option").each(function(){
	//	$(this).text($(this).val());
		$(this).text($(this).text().split('(')[0]);
	});
}

</script>

</head>
<body>
<div class="searchtitle" style="width :1100px;">
<div class="sideBar">
		<div class="box">
			<div class="location">当前位置：个人中心 &gt;手动触发报表</div>
		</div>
	</div>
	<div class="navbar"><div class="navbar-l"></div><div class="navbar-r"></div>
	<div class="navbar-inner"> 
	<b>手动发送报表</b> 
	</div>
	<form method="post" id="doEditForm"	action="">
	<table cellSpacing=0 cellPadding=0  border=0 class="form2column">
		<tr>
			<td class="label">发送的报表：</td>
			<td class="">
				<select name="method" id="method" style="width:200px;" onchange="javascript:showUsers();">
				<option value="">--请选择--</option>
				<option value="internationalOTA">国航_国际旅行航线OTA</option>
				<option value="taobaoFlagship">淘宝_旗舰店与代理人差价报表</option>
				<option value="csairInternationalReport">南航_国际报表</option>
				<option value="CSDomesticReport">南航_国内航线价差</option>
				<option value="CSTaobaoReport">南航_官网淘宝价差</option>
				<option value="ZHPriceReport">深航_官网与渠道价差报表</option>
				<option value="CADomesticReport">国航_国内OTA报表</option>
				</select>
			</td>
			<td class=""></td>
			<td class=""></td>
			
		</tr>
		
		<tr>
			<td class="label">收件人：</td>
			<td style="width:350PX">
				<select multiple="multiple" id="usernames" name="usernames" 
					style="height:200px;width:200px;" ondblclick="addOrRemoveChioce(this)" >
					
				</select>
				<!--  
				<img style="cursor: pointer;"
					src="<%=request.getContextPath() %>/fare/images/but_03.png"
					name="querybutton" id="querybutton" onclick="addChioce()"/>
				-->
				双击即可选中或者删除
			</td>
			<td class=""></td>
			<td class=""></td>
		</tr>
		<tr><td class="label">已选择收件人：</td>
			<td class="" style="width:380px">
				<table id="username"></table>
			</td>
			<td style="height:35px;">
			<%-- <img src="<%=request.getContextPath() %>/fare/fdc/images/but_02.png" name="clearUser" class="btn-normal" onclick="clearAll();" /> --%>
			<input name="clearUser" type="button" class="btn-normal" value="清空" onclick="clearAll()" style="margin-left:18px"/> 
			</td>
			<td class=""></td>
		</tr>
		<!-- <tr>
			<td class="label"> 发送时间日期：</td>
			<td class="" style="width:250px;">
				<input name="start" type="text"	id="start" style="width: 200px"    
							onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'%y-%M-%d'})" readonly="readonly"/>
			</td>
			<td class=""></td>
			<td class=""></td>
		</tr> -->
		
		<tr>
			 <td colspan="4"  style="text-align:center;height:35px;" >
	           <input type="button" value="生成报表" id="btn1" class="btn-normal" onClick="sendReport();"/>
	         </td>
		</tr>
	
	</table>
	</form>
	
	<div  id="wait" style="display:none; text-align:center;" >
		<span ><font color="red"> 正在操作中，请耐心等候...</font></span>
	</div>
		<div class="high_10"></div>
		<div class="navbar">
			<div class="navbar-l">
			</div><div class="navbar-r"></div>
				<div class="navbar-inner"> 
				<b>手动下载报表</b> 
				</div>
				<div class="form_down" id="">
					 <c:if test="${not empty listDataByDate }"> 
						<c:forEach items="${listDataByDate}" var="vos" varStatus="status">
							 <ul class="" onMouseOver="this.className='org'" onMouseOut="this.className='one'"  style="border-bottom: solid 2px #9D9D9D;border-top: solid 2px #9D9D9D;">
							 <li class="title">
							 	<a id=""  class="tooltips" onclick="downloadAllByDate('${vos.createTimeStr}')"><font color="#000000" size="3">${vos.createTimeStr}</font>
							 	 <span><font size="2" style="line-height:12pt;padding:33px 0 0;white-space:nowrap;" >点击批量下载</font></a> 
								
							 </li>
							<c:forEach  items="${vos.listQueEMvo}" var="voLists" varStatus="statusList">
								 <li>
								 	<c:set value="${fn:split(voLists.subject,'_')}"  var="voListSub"/>
									 <a  class="tooltips" id="feed_id" onclick="doDownloadFile('${voLists.attachPath}','${voLists.subject}');">${voListSub[0]} 
									<span><font size="2" style="line-height:12pt;padding:33px 0 0;white-space:nowrap;" >生成时间：${voLists.createTime }<br/>
								<%-- 	<s:if test='voLists.statusStr == "3"'>
										发送状态：成功
									</s:if>
									<s:else>
										发送状态：失败
									</s:else> 
									<br/>--%>
									</font>
									</a>&nbsp;&nbsp;&nbsp;
								 </li>
							 </c:forEach> 
							</ul>
						</c:forEach> 
					</c:if>
					

					</div>
					
	
	<div class="list_page" style="height: 30px;">
 						<jsp:include page="/fare/manualTriggerReport/pageComponent.jsp"></jsp:include>
 					</div>
</div>

	

</div>

</body>
</html>
